class IUP_ANIMATED_LABEL
-- Creates an animated label interface element, which displays an image that 
-- is changed periodically.
--
-- It uses an animation that is simply an IUP_USER with several IUP_IMAGE as 
-- children.
--
-- It inherits from IUP_LABEL all attributes. The IMAGE attribute is 
-- periodically changed by a timer.
--
-- After call "load_images" at IUP, there is available a simple animation to 
-- show an indefinite progress called "IUP_CircleProgressAnimation".
--
-- The IUP-IM functions has two functions that can create an animation from 
-- image files called load_animation and load_animation_frames.

inherit
	IUP_LABEL
		rename
			label_empty as animated_label_empty,
			label as animated_label_with_title
		redefine
			animated_label_empty,
			animated_label_with_title
		end

create {ANY}
	animated_label_empty,
   animated_label,
	animated_label_with_title

feature {ANY}

	animated_label_empty
		-- An empty animated label.
		local
			a_animated_label, p: POINTER
		do
			a_animated_label := int_animated_label(p)
			set_widget(a_animated_label)
		end

	animated_label_with_title (title: STRING)
		-- An empty animated label with the provided title.
		do
			animated_label_empty
			set_title (title)
		end

	animated_label (animation: IUP_USER)
		-- An animated label.
		--
		-- animation: element that contains the list of images.
		local
			a_animated_label: POINTER
		do
			a_animated_label := int_animated_label(animation.widget)
			set_widget(a_animated_label)
		end

	-- Operations

	start
		-- Starts the animation.
		do
			iup_open.set_attribute(Current, "START", "Yes")
		end

	stop
		-- Stop the animation.
		do
			iup_open.set_attribute(Current, "STOP", "Yes")
		end

	-- Attributes

	set_stop_when_hidden (state: BOOLEAN)
		-- Automatically stops the animation when the label is hidden.
		-- Default: "True".
		do
			iup_open.set_attribute(Current, "STOPWHENHIDDEN", boolean_to_yesno(state))
		end
	
	is_running: BOOLEAN
		-- Return True if the animation is running.
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "RUNNING")
			Result := yesno_to_boolean(str)
		end

	set_frame_time (time: REAL_32)
		-- The time between each frame. If the IUP_USER element has a FRAMETIME 
		-- attribute it will be used to set the IUP_ANIMATED_LABEL FRAMETIME 
		-- attribute, but it can be overwritten later on.
		do
			iup_open.set_attribute(Current, "FRAMETIME", time.out)
		end

	get_frame_count: INTEGER
		-- Number of frames in the animation.
		local
			str: STRING
		do
			str := iup_open.get_attribute(Current, "FRAMECOUNT")

			if str.is_integer then
				Result := str.to_integer
			end
		end

	set_animation (name: STRING)
		-- The name of the element that contains the list of images. The value 
		-- passed must be the name of an IUP_USER element with several IUP_IMAGE 
		-- as children.
		do
			iup_open.set_attribute(Current, "ANIMATION", name)
		end

	set_animation_widget (wgt: IUP_USER)
		-- Same as ANIMATION but directly using the widget of the element.
		do
			iup_open.set_attribute_widget(Current, "ANIMATION_HANDLE", wgt)
		end
	

feature {NONE}

	-- Internals
	
	int_animated_label (animation: POINTER): POINTER
		external
			"C inline use %"eiffel-iup.h%""
      alias
			"return IupAnimatedLabel ($animation);"
      end

end

-- The MIT License (MIT)

-- Copyright (c) 2016, 2017, 2019 by German A. Arias

-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in 
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.

